package dao.impl;

import dao.HeroDao;
import entity.Hero;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import util.AliPool;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class HeroDaoImpl implements HeroDao {

    @Override
    public List getpage(int page) throws SQLException {
        String sql="select stid,stname,stpass from student limit ?,10";
        int p=(page-1)*10;
        List list=new ArrayList();
        Connection conn=AliPool.getConn();
        PreparedStatement pst=conn.prepareStatement(sql);
        pst.setInt(1,p);
        ResultSet rs=pst.executeQuery();
        while(rs.next()){
            int id=rs.getInt(1);
            String name = rs.getString(2);
            String pass = rs.getString(3);
            Hero a=new Hero(id,name,pass);
            list.add(a);
        }
        conn.close();
        return list;
    }
}
